home *** CD-ROM | disk | FTP | other *** search
/ Usenet 1993 July / InfoMagic USENET CD-ROM July 1993.ISO / sources / unix / volume25 / pty4 / part06 < prev    next >
Encoding:
Text File  |  1992-02-18  |  61.9 KB  |  2,233 lines

  1. Newsgroups: comp.sources.unix
  2. From: brnstnd@nyu.edu (Dan Bernstein)
  3. Subject: v25i132: Generalized interface to pseudo-tty devices, Part06/09
  4. Sender: unix-sources-moderator@pa.dec.com
  5. Approved: vixie@pa.dec.com
  6.  
  7. Submitted-By: brnstnd@nyu.edu (Dan Bernstein)
  8. Posting-Number: Volume 25, Issue 132
  9. Archive-Name: pty4/part06
  10.  
  11. #! /bin/sh
  12. # This is a shell archive.  Remove anything before this line, then unpack
  13. # it by saving it into a file and typing "sh file".  To overwrite existing
  14. # files, type "sh file -c".  You can also feed this as standard input via
  15. # unshar, or by typing "sh <file", e.g..  If this archive is complete, you
  16. # will see the following message at the end:
  17. #        "End of archive 6 (of 9)."
  18. # Contents:  CALLS CTTYS.draft1 Makefile pty-opts.1 ptytty.c sigsched.3
  19. # Wrapped by vixie@cognition.pa.dec.com on Wed Feb 19 13:35:05 1992
  20. PATH=/bin:/usr/bin:/usr/ucb ; export PATH
  21. if test -f 'CALLS' -a "${1}" != "-c" ; then 
  22.   echo shar: Will not clobber existing file \"'CALLS'\"
  23. else
  24. echo shar: Extracting \"'CALLS'\" \(9477 characters\)
  25. sed "s/^X//" >'CALLS' <<'END_OF_FILE'
  26. pty uses a bunch of syscalls (42 at last count) and library routines.
  27. Calls marked with * are BSD-only or otherwise not available on all UNIX
  28. systems. Calls marked with + are widely available but have different
  29. behavior on different systems---behavior different enough that pty might
  30. not work.
  31. X
  32. X_exit: used in ptyerr.c for almost all exits. Note that pty does not use
  33. X    stdio in any way.
  34. X*accept: used in ptycomm.c`comm_accept, to accept a connection for the
  35. X    master on a descriptor created by comm_read
  36. access: used with F_OK in ptyget.c to check if a pty bank (e.g., ttyq*)
  37. X    exists
  38. X*bind: used in ptycomm.c`comm_read to create the master's comm socket
  39. X*bzero: used inside the system's FD_ZERO macro before select
  40. chdir: used once in the master and once in the sigler, both times in
  41. X    ptymain.c, to switch permanently to PTYDIR.
  42. close: used throughout the program to get rid of a file descriptor.
  43. X    Note that the return value from close is not checked---there's
  44. X    absolutely no way pty could do anything about the descriptor in
  45. X    case of an error, and it's far more important that the
  46. X    descriptor be freed up than that NFS's perverted idea of UNIX
  47. X    I/O be dealt with.
  48. X*connect: used in ptycomm.c`comm_write to connect to a running master
  49. dup: used (1) in ptytty.c to try to find the controlling tty descriptor;
  50. X    (2) in ptyslave.c to move the /dev/ttyxx descriptor to 0/1/2;
  51. X    (3) in ptysecure.c to set up descriptors for /bin/ps
  52. X*dup2: used in ptymisc.c to move a /dev/null descriptor around
  53. execve: used in ptysecure.c to invoke /bin/ps
  54. execvp: used in ptyslave.c to invoke the user's program, after setreuid
  55. X*fchmod: used in ptysecure.c upon a slave tty descriptor
  56. X+fcntl: used with F_GETFL in ptymisc.c (and sigsched.c) to see if a
  57. X    descriptor is open
  58. flock: used in ptymisc.c for generic locking routine (used on log files)
  59. fork: used in ptymain.c (twice) to create master and slave processes;
  60. X    used in ptysecure.c to invoke /bin/ps for security check
  61. free: used in ralloc.c`rfree
  62. X*fstat: used in ptysecure.c upon a slave tty descriptor
  63. X*getdtablesize: used in slave under -E to close all open descriptors;
  64. X    used in ptymaster.c`closeallbut (which is a royal kludge)
  65. X*getpgrp: used in ptytty.c`force_fg to plug into TIOCSPGRP; used in
  66. X    ptymaster.c`contchild in preparation for killpg
  67. getpid: used (1) in the master to fill in a sesslog structure; (2) in
  68. X    ptytty.c`force_fg to plug into getpgrp; (3) in the signaller to
  69. X    send a WINCH to itself after reconnect; (4) in the slave to set
  70. X    its pgrp before exec; (5) in the slave to pass to tctpgrp; (6)
  71. X    to set up numbers for random tty searching; (7) in the master,
  72. X    when fdctrlr asks for its pid; (8) in sigdfl.c to send a signal
  73. X    to itself; (9) in ptysecure.c for various purposes.
  74. X*getpwnam: used only in username.c
  75. X*getpwuid: used only in username.c
  76. X*geteuid: used in ptysecure.c as a secure pseudo-tty owner
  77. getuid: used once in ptytty.c to initialize a uid variable
  78. X+ioctl: used in ptytty.c`ioc to control a tty descriptor; about two
  79. X    dozen BSD-specific ioctls are used in ptytty.c
  80. X+kill: used (1) in the master to tell the child to continue after the
  81. X    sigler says so; (2) in the sigler to tell itself to WINCH after
  82. X    a reconnect; (3) in sigdfl.c to send a signal to itself.
  83. X*killpg: used in ptymaster.c`contchild to continue the child's process
  84. X    group if a straight kill() failed
  85. X*listen: used in ptycomm.c to prepare the master's comm socket for
  86. X    connections
  87. lseek: used in ptylogs.c, sessconnlog.c, and sesslog.c to place a record
  88. X    at a particular spot in a log file
  89. malloc: used in ralloc.c`ralloc
  90. X+open: used (1) in ptyget.c with O_RDWR to open the master and slave
  91. X    sides of a tty; (2) in ptylogs.c with O_RDWR, O_RDWR | O_APPEND,
  92. X    and O_WRONLY | O_APPEND to open UTMP_FILE and WTMP_FILE; (3) in
  93. X    ptymisc.c`forceopen upon /dev/null and /, to attempt to make
  94. X    sure a descriptor is in use; (4) in ptyslave.c (twice) to open
  95. X    /dev/tty with O_RDWR; (5) in ptytty.c`tty_getctrl to open
  96. X    /dev/tty; (6) in sessconnlog.c and sesslog.c, with O_WRONLY |
  97. X    O_CREAT and O_WRONLY | O_APPEND | O_CREAT (both mode 0644), to
  98. X    open the sessnow, sesslog, scnow, and sclog system files for
  99. X    update; (7) in ptysecure.c for various purposes.
  100. pipe: used (1) in ptymain.c to create pipes from the master to the
  101. X    sigler and slave, so that there's no race between the master
  102. X    setting up files and the sigler and slave starting; (2) in
  103. X    ptysigler.c to create the master->sigler and sigler->master
  104. X    pipes just before reconnect; (3) in ptysecure.c to create an
  105. X    output pipe for /bin/ps.
  106. read
  107. X*recvmsg: used in ptycomm.c to receive a descriptor from a UNIX-domain
  108. X    socket. Note that recvmsg() is buggy in most BSD variants.
  109. X*select: used (1) in ptymisc.c to pause briefly; (2) in sigsched.c to
  110. X    check for usable descriptors.
  111. X*sendmsg: used in ptycomm.c to send a descriptor down a UNIX-domain
  112. X    socket. Note that sendmsg() is buggy in some BSD variants.
  113. X*setpgrp: used in ptyslave.c to set up pgrp of slave
  114. X*setreuid: used in ptyslave.c to make sure that slave runs as real uid;
  115. X    used in ptysecure.c to make sure that /bin/ps runs as real uid;
  116. X    used in ptymain.c to make sure that master is safe from user
  117. X*sigblock: used in sigdfl.c and sigsched.c for various purposes
  118. X+signal: used in various spots to set handlers to SIG_{IGN,DFL}
  119. X*sigsetmask: used in sigdfl.c and sigsched.c for various purposes
  120. X*sigvec: used in sigdfl.c and sigsched.c to install signal handlers
  121. X*socket: used in ptycomm.c`comm_{read,write} to set up comm socket
  122. strcpy: used in env.c for various purposes
  123. strlen: used throughout the code for various purposes
  124. strncmp: used in env.c and ptylogs.c
  125. strncpy: used in ptylogs.c, sessconnlog.c, sesslog.c
  126. time: used in ptymisc.c`now
  127. unlink: used only in ptycomm.c, upon a restricted pathname, to remove
  128. X    an obsolete communications socket.
  129. X*wait3: used in both master and sigler to wait for children (in the
  130. X    latter case, simply to get rid of zombies), with NOHANG and
  131. X    UNTRACED.
  132. write
  133. X
  134. Note that pty also depends on environ and errno.
  135. X
  136. The BSD-specific calls can be divided into several groups:
  137. X
  138. A (pty allocation). Lots of vendors have added pseudo-ttys. In the BSD
  139. world, everyone simply copied what Berkeley did. Unfortunately, System V
  140. is graced with at least nine pseudo-tty allocation mechanisms; there are
  141. probably many more which I haven't seen. ptyget.c and ptysecure.c have
  142. to be completely rewritten for each new allocation design. On the other
  143. hand, there must be code which uses the ptys on that system, so this is
  144. certainly a doable job.
  145. X
  146. B (select). select (and the associated FD_ZERO [using bzero], FD_ISSET,
  147. and FD_SET macros) is the foundation of the sigsched library, which
  148. literally runs everything. select also uses the largest part of pty's
  149. run time. It would be incredibly difficult to simulate select() with a
  150. less powerful mechanism, such as poll(). I would have to be exceedingly
  151. bored before attempting to port pty to a system without select().
  152. X
  153. C (communication, including fd passing). accept, bind, connect, listen,
  154. recvmsg, sendmsg, and socket are isolated inside ptycomm.c. You can rip
  155. out the entire ptycomm.c mechanism and replace it with anything which
  156. X(1) allows client-server connections with some security; (2) lets
  157. read(), write(), and select() work; (3) provides file descriptor
  158. passing; (4) allows a two-way connection on a single descriptor. Most
  159. streams facilities can handle (3). Note that if the file descriptor
  160. passing mechanism isn't as buggy as BSD's, you can get rid of
  161. ptymisc.c`gaargh.
  162. X
  163. D (job control). getpgrp(), setpgrp(), the TIOCSPGRP and TIOCGPGRP
  164. ioctls, various signals, kill(,SIGCONT), killpg, and wait3 are all part
  165. of the BSD job control system. pty puts quite a bit of effort into
  166. handling job control, but not nearly as much as the previous version. I
  167. really can't guess what will go wrong if you simply rip out all the job
  168. control code and replace wait3() with an appropriate wait().
  169. X
  170. XE (tty handling). SIGWINCH and some two dozen tty ioctls all depend on
  171. the BSD tty system. SIGWINCH is easy to take care of---it's already
  172. X#ifdef'ed for TTY_WINDOWS. (pty works under BSD 4.2, which doesn't have
  173. SIGWINCH.) The other tty ioctls are isolated inside ptytty.c, which I
  174. will probably rewrite for POSIX if and when somebody asks me to.
  175. January 1992 update: Okay, I've now implemented TTY_TERMIO. POSIX, for
  176. some absolutely idiotic reason, doesn't stick to the traditional header
  177. files, but TTY_TERMIO should be good enough for systems with System V
  178. tty handling.
  179. X
  180. XF (signal management). sigblock, sigsetmask, sigvec, and good old signal
  181. are all used throughout the pty code. POSIX can handle all of them, and
  182. I will do this port soon. System V cannot---it's very important that pty
  183. have reliable signal handling.
  184. X
  185. G (easy stuff). dup2, fcntl(,F_GETFL,0), getdtablesize, getpwnam,
  186. getpwuid, fchmod, fstat, and setreuid are all reasonably easy to handle.
  187. dup2() can be written in terms of F_DUPFD for System V; in fact, pty
  188. only uses it in a situation where it should be a no-op! (See
  189. ptymisc`forceopen and the calls to forceopen in ptymain.c.) F_GETFL is,
  190. I believe, available on all modern UNIX-like systems. getdtablesize can
  191. be replaced by NOFILE. setreuid(uid,uid) is essentially equivalent to
  192. setuid(uid). getpwnam() and getpwuid() appear on most systems, and when
  193. they don't appear, they're easy enough to write (just scan /etc/passwd).
  194. fchmod and fstat can be replaced by chmod and stat---they're only used
  195. in situations where the pathname is known (viz., a slave tty).
  196. END_OF_FILE
  197. if test 9477 -ne `wc -c <'CALLS'`; then
  198.     echo shar: \"'CALLS'\" unpacked with wrong size!
  199. fi
  200. # end of 'CALLS'
  201. fi
  202. if test -f 'CTTYS.draft1' -a "${1}" != "-c" ; then 
  203.   echo shar: Will not clobber existing file \"'CTTYS.draft1'\"
  204. else
  205. echo shar: Extracting \"'CTTYS.draft1'\" \(9430 characters\)
  206. sed "s/^X//" >'CTTYS.draft1' <<'END_OF_FILE'
  207. Controlling Ttys: A UNIX Horror Story
  208. Daniel J. Bernstein
  209. draft 1
  210. X10/6/91
  211. X
  212. X
  213. X1. Introduction
  214. X
  215. X     ``Normal file access permissions handle security.''
  216. X            ---POSIX.1-1988 rationale, B.7.1.1.4
  217. X
  218. When a user logs into a UNIX system, he is assigned a _tty_ which echoes
  219. and processes his characters, lets him edit command lines, handles flow
  220. control on output, and so on. The user's shell reads and writes from the
  221. tty. Messages sent by the ``write'' and ``talk'' user communication
  222. commands are also sent through the tty. In fact, ttys (also called
  223. X_terminals_, _teletypes_, and _typewriters_) are the focal point of
  224. almost all interaction between a user and the system.
  225. X
  226. Ttys come in two flavors: hardwired ttys and pseudo-ttys. Hardwired ttys
  227. are connected directly to a physical device, such as a modem.
  228. Pseudo-ttys may be dynamically connected to any process. For instance,
  229. the telnetd program links a pseudo-tty with each network connection.
  230. X
  231. Unlike pipes, ttys have traditionally been assigned a name in the
  232. filesystem: /dev/console, for instance, is a hardwired tty, and
  233. X/dev/ttyp7 is a pseudo-tty. The primary reason for these files is to
  234. support user-to-user communication. The system typically assigns
  235. ownership of tty files to the current user. That way the user can change
  236. his tty modes to control whether ``write'' and ``talk'' messages are
  237. allowed.
  238. X
  239. Occasionally a program (or more often a script) wants to send messages
  240. to the current tty, no matter what redirection has been put on stdout
  241. and stderr. (The author defers judgment on whether this is a sensible
  242. thing for programs to do.) More often, a user wants to know what the
  243. current tty is, to keep track of what he's doing. One obvious solution
  244. to both problems is to keep the current tty in an environment variable,
  245. like TTY=/dev/ttyp7. Then a ``tty'' program can simply echo $TTY, and
  246. programs which want to talk to the user can open $TTY.
  247. X
  248. Unfortunately, UNIX never acquired such a simple user-mode solution.
  249. Instead each process was assigned a ``controlling tty'', something which
  250. the kernel kept track of and treated specially. That is where the horror
  251. story begins.
  252. X
  253. X
  254. X2. Controlling ttys
  255. X
  256. Processes start without a controlling terminal. When a process without a
  257. controlling tty (also called ``ctty'') opens a tty, it is assigned that
  258. ctty, and the ctty is preserved through fork() and exec(). Different
  259. UNIX systems have various methods of removing the association between a
  260. process and its controlling tty. We will return to this subject below.
  261. X
  262. A special file, /dev/tty, is accessible to all processes at all times.
  263. When a process opens /dev/tty, it gets a valid descriptor to its ctty,
  264. or ENODEV if it does not have a ctty. The protection on the actual tty
  265. file is irrelevant to /dev/tty.
  266. X
  267. Under BSD 4.2, the controlling tty has almost no effects on job control.
  268. BSD 4.3 added some rules in the name of job control security. POSIX went
  269. much farther, and formalized controlling ttys into ``sessions.'' Each
  270. process is associated with a session, and various ad-hoc session rules
  271. are thrown in to complicate job control and signal processing in
  272. general. (For instance, a process can only stop if its parent is in the
  273. X*same* session but a *different* process group.) The problem of
  274. supporting job control without losing security became an excuse for
  275. controlling terminals and sessions.
  276. X
  277. At this point we can identify six separate forms of access to a tty
  278. device, say /dev/ttyp7, by a process:
  279. X
  280. X   O (ownership) access: uid owns /dev/ttyp7
  281. X   P (protection) access: uid has permision to open /dev/ttyp7
  282. X   C (ctty) access: current ctty is /dev/ttyp7
  283. X   T (/dev/tty) access: file descriptor to /dev/tty, pointing to /dev/ttyp7
  284. X   S (slave) access: file descriptor to /dev/ttyp7 itself
  285. X   M (master) access: file descriptor to /dev/ptyp7 (pseudo-ttys only)
  286. X
  287. X(The names ``master'' and ``slave'' are pseudo-tty terminology.)
  288. The system lets a process acquire access in several ways: A process with
  289. O access can gain P access. A process with P access can gain S access. A
  290. process with C access can gain T access. A process with M or S access
  291. can gain C access. A process can gain M access (by opening /dev/ptyp7)
  292. if no other process has M access.
  293. X
  294. Under BSD, to shed C access, a process must gain T access (i.e., open
  295. X/dev/tty) and perform the TIOCNOTTY ioctl. Unfortunately, if any process
  296. applies the TIOCEXCL ioctl to the tty, no process will be able to open
  297. X/dev/tty itself until some process does TIOCNXCL. A program stuck under
  298. a tty with TIOCEXCL set has *absolutely no reliable way* to dissociate
  299. itself from that tty. (Perhaps this is not a surprise given that there
  300. is also absolutely no reliable way for a process to figure out what tty
  301. it is associated with in the first place.)
  302. X
  303. And the TIOCEXCL problem pales beside the number of twists and turns
  304. introduced by POSIX. Obviously this is not a simple system to implement,
  305. use, understand, or make secure.
  306. X
  307. X
  308. X3. Security
  309. X
  310. Steve Bellovin pointed out years ago ([]), as did this author ([]), that
  311. an attacker could abuse controlling ttys to take almost complete control
  312. of the system. Put simply, it is very difficult to detect, let alone
  313. revoke, whether another user has S, T, or C access to a tty.
  314. X
  315. BSD 4.2 and its descendants have a vhangup() system call meant to revoke
  316. access to a tty. Unfortunately, it doesn't work on most systems, and
  317. only revokes S access on the rest. (This author considers vhangup() a
  318. joke in very poor taste.)
  319. X
  320. Several vendors have attempted to fix this problem. The Convex UNIX 8.0
  321. documentation, for instance, says that the holes are gone. They're not.
  322. Convex insisted that its system was secure until the author sent
  323. explicit code showing how to break tty security.
  324. X
  325. Similarly, after a series of Internet breakins using tty security holes,
  326. Sun distributed a patch to their SunOS 4.1 telnetd and rlogind
  327. supposedly fixing the problems ([]). (It is worth noting that
  328. essentially the same fix appeared in version 3.0 of the author's pty
  329. package [] several months before.) Although the patch was enough to
  330. temporarily stop the attacks, it did not close C access, and hence was
  331. not enough.
  332. X
  333. Version 4.0 of the author's pty package ([]) includes security tests
  334. which detect all possible forms of tty access, and which work on any BSD
  335. system. It is obscene that such measures have proven necessary. In the
  336. meantime, crackers from the Netherlands and elsewhere have broken into
  337. literally thousands of Internet accounts, taking advantage of tty
  338. security holes at will.
  339. X
  340. X
  341. X4. Simplifications
  342. X
  343. Under SunOS 4.1, BSD 4.4, and a few other systems, T access has been
  344. removed. A process which opens /dev/tty will get a full-fledged
  345. descriptor to /dev/ttyp7; there is no longer any distinction between
  346. X/dev/tty and the real tty file it refers to, except that /dev/tty is
  347. always completely unprotected.
  348. X
  349. Any excuse for controlling terminals or POSIX sessions on the basis of
  350. job control security is completely invalid. As pointed out by the author
  351. in [], the job control system can be made much simpler, easier to use,
  352. and simultaneously completely secure, with absolutely no help from cttys
  353. or POSIX sessions. As suggested above, the controlling tty can be passed
  354. in the TTY environment variable. C (and T) access, as well as POSIX
  355. sessions, can simply disappear.
  356. X
  357. X(Apparently the disappearance of cttys and POSIX sessions would remove
  358. absolutely no functionality, from either the user's or the application's
  359. point of view; and of course it would make a much cleaner system and
  360. standard if it were officially adopted. The author would greatly love to
  361. hear from any proponents of POSIX sessions who can explain what features
  362. they provide, especially in light of his new, simple, secure job control
  363. system, when in fact vendors, programmers, and users wouldn't care if
  364. setsid() became a no-op.)
  365. X
  366. XFor backwards compatibility it would be useful to keep a /dev/tty device
  367. so that programs do not have to be changed to use $TTY. Applications
  368. running under the author's pty program can normally access the tty
  369. through descriptor 3, so an easy solution here is to let /dev/tty be a
  370. simple driver which dup()s fd 3.
  371. X
  372. The only other useful function of a controlling terminal---viz., to help
  373. the user categorize processes---is easily taken care of at user level.
  374. ps can use $TTY for its output. Accounting could be by pid (as it should
  375. be) instead of by the marginally useful ac_tty.
  376. X
  377. We're still left with O and P access---ttys are still in the filesystem.
  378. Given fd 3 support, programs which want to talk to the user don't need
  379. to open() ttys. The other use of ttys in the filesystem is user-to-user
  380. communication, but there are several replacement communication systems
  381. which depend on users running their own daemons rather than having a
  382. writable tty file. So tty files can disappear. Rather than opening tty
  383. files, programs can create ttys with a new system call. Then ttys will
  384. be much more like pipes, which may be accessed only through a pair of
  385. descriptors.
  386. X
  387. If these simplifications had been made when UNIX was young, before it
  388. was used by millions of people, then maybe the controlling terminal
  389. horror story would not have lasted so long or caused so much damage.
  390. XFortunately, the story will end soon, as in October 1992 the author will
  391. distribute code which anyone can use to exploit these holes. Any vendor
  392. which wants to stay in business will fix its systems long before then.
  393. X
  394. X
  395. References
  396. X
  397. XXXX
  398. END_OF_FILE
  399. if test 9430 -ne `wc -c <'CTTYS.draft1'`; then
  400.     echo shar: \"'CTTYS.draft1'\" unpacked with wrong size!
  401. fi
  402. # end of 'CTTYS.draft1'
  403. fi
  404. if test -f 'Makefile' -a "${1}" != "-c" ; then 
  405.   echo shar: Will not clobber existing file \"'Makefile'\"
  406. else
  407. echo shar: Extracting \"'Makefile'\" \(10626 characters\)
  408. sed "s/^X//" >'Makefile' <<'END_OF_FILE'
  409. CC=cc -s
  410. OPTMZ=-O
  411. X# OPTMZ is used below for time-critical modules
  412. CPP=cc -E
  413. X# alternative: CPP=/lib/cpp <
  414. PTYLIBS=
  415. X
  416. all: pty clones sessstuff ttymisc misc
  417. X
  418. target-list:
  419. X    @echo 'target-list all clones sessstuff ttymisc misc INSTALL CHECKCONF shar clean lint'
  420. X
  421. clones: biff mesg wall write lock script users tty who whoami
  422. X
  423. sessstuff: sess sesslist sessname sessmenu disconnect reconnect sesswho sesswhere sesskill
  424. X
  425. ttymisc: tiocsti condom ttyprotect utmpinit ttydetach checkptys exclon excloff wtmprotate sessrotate sclogrotate sessnowinit scnowinit
  426. X
  427. misc: tscript script.tidy waitfor argv0 ctrlv nobuf tplay trecord
  428. X
  429. INSTALL: INSTALL.c
  430. X    $(CC) -o INSTALL INSTALL.c
  431. X
  432. CHECKCONF: CHECKCONF.c
  433. X    $(CC) -o CHECKCONF CHECKCONF.c
  434. X
  435. sessnowinit: sessnowinit.sh
  436. X    $(CPP) sessnowinit.sh | tail -2 | tr -d '"' | sed 's/^X/#/' > sessnowinit
  437. X    chmod 700 sessnowinit
  438. X
  439. scnowinit: scnowinit.sh
  440. X    $(CPP) scnowinit.sh | tail -2 | tr -d '"' | sed 's/^X/#/' > scnowinit
  441. X    chmod 700 scnowinit
  442. X
  443. sessrotate: sessrotate.sh
  444. X    $(CPP) sessrotate.sh | tail -12 | tr -d '"' | sed 's/^X/#/' > sessrotate
  445. X    chmod 700 sessrotate
  446. X
  447. sclogrotate: sclogrotate.sh
  448. X    $(CPP) sclogrotate.sh | tail -12 | tr -d '"' | sed 's/^X/#/' > sclogrotate
  449. X    chmod 700 sclogrotate
  450. X
  451. wtmprotate: wtmprotate.sh
  452. X    $(CPP) wtmprotate.sh | tail -12 | tr -d '"' | sed 's/^X/#/' > wtmprotate
  453. X    chmod 700 wtmprotate
  454. X
  455. nobuf: nobuf.sh
  456. X    cp nobuf.sh nobuf
  457. X    chmod 700 nobuf
  458. X
  459. script.tidy: script.tidy.sh
  460. X    tr '83' '\010\015' < script.tidy.sh > script.tidy
  461. X    chmod 700 script.tidy
  462. X
  463. sess: sess.sh
  464. X    cp sess.sh sess
  465. X    chmod 700 sess
  466. X
  467. tscript: tscript.sh
  468. X    cp tscript.sh tscript
  469. X    chmod 700 tscript
  470. X
  471. script: script.sh
  472. X    cp script.sh script
  473. X    chmod 700 script
  474. X
  475. ttyprotect: ttyprotect.sh
  476. X    cp ttyprotect.sh ttyprotect
  477. X    chmod 700 ttyprotect
  478. X
  479. condom: ttyprotect.sh
  480. X    cp ttyprotect.sh condom
  481. X    chmod 700 condom
  482. X
  483. sesskill: sesskill.o ptycomm.o getopt.o env.o ralloc.o ptymisc.o fmt.o scan.o
  484. X    $(CC) -o sesskill sesskill.o ptycomm.o getopt.o env.o ralloc.o ptymisc.o fmt.o scan.o
  485. X
  486. tplay: tplay.o sigsched.o timer.o ralloc.o
  487. X    $(CC) -o tplay tplay.o sigsched.o timer.o ralloc.o
  488. X
  489. trecord: trecord.o sigsched.o timer.o ralloc.o
  490. X    $(CC) -o trecord trecord.o sigsched.o timer.o ralloc.o
  491. X
  492. ctrlv: ctrlv.o ptymisc.o scan.o
  493. X    $(CC) -o ctrlv ctrlv.o ptymisc.o scan.o
  494. X
  495. checkptys: checkptys.o
  496. X    $(CC) -o checkptys checkptys.o
  497. X
  498. ttydetach: ttydetach.o env.o ralloc.o
  499. X    $(CC) -o ttydetach ttydetach.o env.o ralloc.o
  500. X
  501. excloff: excloff.o
  502. X    $(CC) -o excloff excloff.o
  503. X
  504. exclon: exclon.o
  505. X    $(CC) -o exclon exclon.o
  506. X
  507. argv0: argv0.o
  508. X    $(CC) -o argv0 argv0.o
  509. X
  510. waitfor: waitfor.o
  511. X    $(CC) -o waitfor waitfor.o
  512. X
  513. tty: tty.o getopt.o
  514. X    $(CC) -o tty tty.o getopt.o
  515. X
  516. utmpinit: utmpinit.o ptymisc.o scan.o
  517. X    $(CC) -o utmpinit utmpinit.o ptymisc.o scan.o
  518. X
  519. who: who.o getopt.o fmt.o
  520. X    $(CC) -o who who.o getopt.o fmt.o
  521. X
  522. whoami: whoami.o username.o fmt.o scan.o
  523. X    $(CC) -o whoami whoami.o username.o fmt.o scan.o
  524. X
  525. users: users.o radixsort.o ralloc.o
  526. X    $(CC) -o users users.o radixsort.o ralloc.o
  527. X
  528. lock: lock.o
  529. X    $(CC) -o lock lock.o -lcurses
  530. X
  531. sesswhere: sesswhere.o sessconnlog.o getopt.o fmt.o ptymisc.o scan.o
  532. X    $(CC) -o sesswhere sesswhere.o sessconnlog.o getopt.o fmt.o ptymisc.o scan.o
  533. X
  534. sesswho: sesswho.o sesslog.o getopt.o ptymisc.o scan.o
  535. X    $(CC) -o sesswho sesswho.o sesslog.o getopt.o ptymisc.o scan.o
  536. X
  537. sesslist: sesslist.o ptycomm.o fmt.o getopt.o ptymisc.o scan.o
  538. X    $(CC) -o sesslist sesslist.o ptycomm.o fmt.o getopt.o ptymisc.o scan.o
  539. X
  540. disconnect: disconnect.o ptycomm.o getopt.o env.o ralloc.o ptymisc.o fmt.o scan.o
  541. X    $(CC) -o disconnect disconnect.o ptycomm.o getopt.o env.o ralloc.o ptymisc.o fmt.o scan.o
  542. X
  543. reconnect: reconnect.o ptycomm.o getopt.o env.o ralloc.o ptymisc.o fmt.o scan.o
  544. X    $(CC) -o reconnect reconnect.o ptycomm.o getopt.o env.o ralloc.o ptymisc.o fmt.o scan.o
  545. X
  546. sessmenu: sessmenu.o
  547. X    $(CC) -o sessmenu sessmenu.o
  548. X
  549. sessname: sessname.o ptycomm.o getopt.o env.o ralloc.o ptymisc.o fmt.o scan.o
  550. X    $(CC) -o sessname sessname.o ptycomm.o getopt.o env.o ralloc.o ptymisc.o fmt.o scan.o
  551. X
  552. biff: biff.o
  553. X    $(CC) -o biff biff.o
  554. X
  555. mesg: mesg.o
  556. X    $(CC) -o mesg mesg.o
  557. X
  558. tiocsti: tiocsti.o
  559. X    $(CC) -o tiocsti tiocsti.o
  560. X
  561. write: write.o fmt.o
  562. X    $(CC) -o write write.o fmt.o
  563. X
  564. wall: wall.o fmt.o
  565. X    $(CC) -o wall wall.o fmt.o
  566. X
  567. pty: env.o fmt.o getoptquiet.o ptycomm.o ptyerr.o ptyget.o ptylogs.o ptymain.o ptymaster.o ptymisc.o ptysecure.o ptysigler.o ptyslave.o ptytexts.o ptytty.o ralloc.o scan.o sessconnlog.o sesslog.o sigdfl.o sigsched.o username.o
  568. X    $(CC) -o pty env.o fmt.o getoptquiet.o ptycomm.o ptyerr.o ptyget.o ptylogs.o ptymain.o ptymaster.o ptymisc.o ptysecure.o ptysigler.o ptyslave.o ptytexts.o ptytty.o ralloc.o scan.o sessconnlog.o sesslog.o sigdfl.o sigsched.o username.o $(PTYLIBS)
  569. X
  570. env.o: env.c
  571. X    $(CC) -c env.c
  572. X
  573. fmt.o: fmt.c
  574. X    $(CC) -c fmt.c
  575. X
  576. getoptquiet.o: getoptquiet.c
  577. X    $(CC) -c getoptquiet.c
  578. X
  579. getopt.o: getopt.c
  580. X    $(CC) -c getopt.c
  581. X
  582. ptycomm.o: ptycomm.c
  583. X    $(CC) -c ptycomm.c
  584. X
  585. ptyerr.o: ptyerr.c
  586. X    $(CC) -c ptyerr.c
  587. X
  588. ptyget.o: ptyget.c
  589. X    $(CC) -c ptyget.c
  590. X
  591. ptylogs.o: ptylogs.c
  592. X    $(CC) -c ptylogs.c
  593. X
  594. ptymain.o: ptymain.c
  595. X    $(CC) -c ptymain.c
  596. X
  597. ptymaster.o: ptymaster.c
  598. X    $(CC) -c ptymaster.c
  599. X
  600. ptymisc.o: ptymisc.c
  601. X    $(CC) -c ptymisc.c
  602. X
  603. ptysecure.o: ptysecure.c
  604. X    $(CC) -c ptysecure.c
  605. X
  606. ptysigler.o: ptysigler.c
  607. X    $(CC) -c ptysigler.c
  608. X
  609. ptyslave.o: ptyslave.c
  610. X    $(CC) -c ptyslave.c
  611. X
  612. ptytexts.o: ptytexts.c
  613. X    $(CC) -c ptytexts.c
  614. X
  615. ptytty.o: ptytty.c
  616. X    $(CC) -c ptytty.c
  617. X
  618. ralloc.o: ralloc.c
  619. X    $(CC) -c ralloc.c
  620. X
  621. scan.o: scan.c
  622. X    $(CC) -c scan.c
  623. X
  624. sessconnlog.o: sessconnlog.c
  625. X    $(CC) -c sessconnlog.c
  626. X
  627. sesslog.o: sesslog.c
  628. X    $(CC) -c sesslog.c
  629. X
  630. sigdfl.o: sigdfl.c
  631. X    $(CC) -c sigdfl.c
  632. X
  633. sigsched.o: sigsched.c
  634. X    $(CC) -c sigsched.c
  635. X
  636. username.o: username.c
  637. X    $(CC) -c username.c
  638. X
  639. write.o: write.c
  640. X    $(CC) -c write.c
  641. X
  642. wall.o: wall.c
  643. X    $(CC) -c wall.c
  644. X
  645. tiocsti.o: tiocsti.c
  646. X    $(CC) -c tiocsti.c
  647. X
  648. biff.o: biff.c
  649. X    $(CC) -c biff.c
  650. X
  651. mesg.o: mesg.c
  652. X    $(CC) -c mesg.c
  653. X
  654. sesslist.o: sesslist.c
  655. X    $(CC) -c sesslist.c
  656. X
  657. sessname.o: sessname.c
  658. X    $(CC) -c sessname.c
  659. X
  660. sessmenu.o: sessmenu.c
  661. X    $(CC) -c sessmenu.c
  662. X
  663. disconnect.o: disconnect.c
  664. X    $(CC) -c disconnect.c
  665. X
  666. reconnect.o: reconnect.c
  667. X    $(CC) -c reconnect.c
  668. X
  669. sesswho.o: sesswho.c
  670. X    $(CC) -c sesswho.c
  671. X
  672. sesswhere.o: sesswhere.c
  673. X    $(CC) -c sesswhere.c
  674. X
  675. lock.o: lock.c
  676. X    $(CC) -c lock.c
  677. X
  678. users.o: users.c
  679. X    $(CC) -c users.c
  680. X
  681. tty.o: tty.c
  682. X    $(CC) -c tty.c
  683. X
  684. utmpinit.o: utmpinit.c
  685. X    $(CC) -c utmpinit.c
  686. X
  687. who.o: who.c
  688. X    $(CC) -c who.c
  689. X
  690. whoami.o: whoami.c
  691. X    $(CC) -c whoami.c
  692. X
  693. sesskill.o: sesskill.c
  694. X    $(CC) -c sesskill.c
  695. X
  696. waitfor.o: waitfor.c
  697. X    $(CC) -c waitfor.c
  698. X
  699. ctrlv.o: ctrlv.c
  700. X    $(CC) -c ctrlv.c
  701. X
  702. ttydetach.o: ttydetach.c
  703. X    $(CC) -c ttydetach.c
  704. X
  705. checkptys.o: checkptys.c
  706. X    $(CC) -c checkptys.c
  707. X
  708. excloff.o: excloff.c
  709. X    $(CC) -c excloff.c
  710. X
  711. exclon.o: exclon.c
  712. X    $(CC) -c exclon.c
  713. X
  714. argv0.o: argv0.c
  715. X    $(CC) -c argv0.c
  716. X
  717. radixsort.o: radixsort.c
  718. X    $(CC) $(OPTMZ) -c radixsort.c
  719. X
  720. tplay.o: tplay.c
  721. X    $(CC) -c tplay.c
  722. X
  723. trecord.o: trecord.c
  724. X    $(CC) -c trecord.c
  725. X
  726. timer.o: timer.c
  727. X    $(CC) -c timer.c
  728. X
  729. shar: FILES
  730. X    shar `cat FILES` > pty.shar
  731. X    chmod 400 pty.shar
  732. X
  733. clean: OBJECTS BINARIES
  734. X    rm -f `cat OBJECTS BINARIES`
  735. X
  736. lint:
  737. X    lint -haxc pty*.c getopt.c ralloc.c env.c fmt.c scan.c sessconnlog.c sesslog.c sigdfl.c username.c sigsched.c
  738. X
  739. X# automatically generated past this
  740. X
  741. CHECKCONF: config/fdsettrouble.h config/genericptr.h config/devmty.h
  742. CHECKCONF: config/devsty.h config/posix.h config/ptybin.h config/ptydir.h
  743. CHECKCONF: config/ptyext.h config/ptygroup.h config/ptylongname.h
  744. CHECKCONF: config/ptymodes.h config/ptyopts.h config/ttyopts.h
  745. CHECKCONF: config/sessconnfile.h config/sessfile.h
  746. CHECKCONF: config/utmpfile.h config/wtmpfile.h
  747. INSTALL: config/ptybin.h config/ptydir.h
  748. INSTALL: config/ptygroup.h config/sessconnfile.h config/sessfile.h
  749. INSTALL: config/utmpfile.h config/wtmpfile.h
  750. INSTALL: config/ptygroup.h
  751. checkptys.o: config/devmty.h config/devsty.h config/posix.h config/ptybin.h
  752. checkptys.o: config/ptydir.h config/ptyext.h config/ptygroup.h
  753. checkptys.o: config/ptymodes.h config/ptyopts.h config/sessconnfile.h
  754. checkptys.o: config/sessfile.h config/utmpfile.h
  755. checkptys.o: config/wtmpfile.h
  756. ctrlv.o: ptymisc.h
  757. disconnect.o: ptymisc.h ptycomm.h
  758. disconnect.o: config/ptydir.h getopt.h env.h
  759. env.o: env.h ralloc.h
  760. fmt.o: fmt.h
  761. getopt.o: getopt.h
  762. getoptquiet.o: getoptquiet.h
  763. ptycomm.o: fmt.h config/ptyext.h ptycomm.h ptymisc.h
  764. ptyerr.o: getoptquiet.h fmt.h ptyerr.h ralloc.h
  765. ptyget.o: ptyget.h
  766. ptyget.o: config/ptyext.h config/devmty.h config/devsty.h ptysecure.h
  767. ptylogs.o: fmt.h config/utmpfile.h config/wtmpfile.h
  768. ptylogs.o: ptymisc.h ptylogs.h config/sysv.h
  769. ptymain.o: sigsched.h getoptquiet.h ralloc.h env.h fmt.h config/ptydir.h
  770. ptymain.o: config/ttyopts.h config/ptyopts.h config/posix.h ptyget.h ptytty.h
  771. ptymain.o: config/ttyopts.h ptylogs.h ptymisc.h
  772. ptymain.o: ptytexts.h ptycomm.h ptymaster.h ptysigler.h ptyerr.h ptyslave.h
  773. ptymain.o: sesslog.h sessconnlog.h
  774. ptymaster.o: sigsched.h ralloc.h
  775. ptymaster.o: config/ttyopts.h config/ptylongname.h sesslog.h sessconnlog.h
  776. ptymaster.o: ptyget.h ptymisc.h ptyerr.h ptytty.h
  777. ptymaster.o: config/ttyopts.h ptycomm.h ptymaster.h
  778. ptymisc.o: ptymisc.h config/fdsettrouble.h
  779. ptysecure.o: ptysecure.h ptytty.h
  780. ptysecure.o: config/ttyopts.h config/ptymodes.h config/ptygroup.h
  781. ptysigler.o: sigsched.h
  782. ptysigler.o: sigdfl.h fmt.h sessconnlog.h ptytty.h
  783. ptysigler.o: config/ttyopts.h ptycomm.h ptymisc.h ptyerr.h config/ttyopts.h
  784. ptysigler.o: ptysigler.h
  785. ptyslave.o: fmt.h ptyerr.h
  786. ptyslave.o: ptyslave.h ralloc.h
  787. ptytexts.o: ptytexts.h
  788. ptytty.o: config/genericptr.h
  789. ptytty.o: config/ttyopts.h ptytty.h config/ttyopts.h
  790. ralloc.o: ralloc.h sod.h
  791. reconnect.o: ptymisc.h ptycomm.h
  792. reconnect.o: config/ptydir.h getopt.h env.h
  793. scan.o: scan.h
  794. sessconnlog.o: sessconnlog.h ptymisc.h
  795. sessconnlog.o: config/sessconnfile.h config/ptyext.h
  796. sesskill.o: ptycomm.h config/ptydir.h getopt.h
  797. sesskill.o: env.h
  798. sesslist.o: config/ptydir.h
  799. sesslist.o: config/ptylongname.h fmt.h scan.h getopt.h ptycomm.h
  800. sesslog.o: sesslog.h
  801. sesslog.o: ptymisc.h config/sessfile.h config/ptyext.h
  802. sessname.o: ptycomm.h config/ptydir.h
  803. sessname.o: config/ptylongname.h getopt.h env.h
  804. sesswhere.o: fmt.h getopt.h sessconnlog.h
  805. sesswhere.o: config/sessconnfile.h
  806. sesswho.o: getopt.h sesslog.h config/sessfile.h
  807. sigdfl.o: sigdfl.h
  808. sigsched.o: config/fdsettrouble.h sigsched.h
  809. sigsched.o: ralloc.h sod.h
  810. timer.o: sigsched.h sod.h
  811. timer.o: timer.h sigsched.h ralloc.h
  812. tplay.o: sigsched.h timer.h sigsched.h
  813. trecord.o: timer.h sigsched.h
  814. tty.o: getopt.h
  815. ttydetach.o: env.h config/posix.h
  816. username.o: username.h fmt.h scan.h
  817. users.o: config/utmpfile.h
  818. users.o: radixsort.h sod.h ralloc.h
  819. utmpinit.o: config/utmpfile.h
  820. utmpinit.o: ptymisc.h
  821. wall.o: fmt.h config/utmpfile.h
  822. who.o: config/utmpfile.h getopt.h fmt.h
  823. whoami.o: username.h
  824. write.o: config/utmpfile.h fmt.h
  825. END_OF_FILE
  826. if test 10626 -ne `wc -c <'Makefile'`; then
  827.     echo shar: \"'Makefile'\" unpacked with wrong size!
  828. fi
  829. # end of 'Makefile'
  830. fi
  831. if test -f 'pty-opts.1' -a "${1}" != "-c" ; then 
  832.   echo shar: Will not clobber existing file \"'pty-opts.1'\"
  833. else
  834. echo shar: Extracting \"'pty-opts.1'\" \(9331 characters\)
  835. sed "s/^X//" >'pty-opts.1' <<'END_OF_FILE'
  836. X.TH pty-opts 1
  837. X.SH NAME
  838. pty-opts \- run a program under a pseudo-terminal session
  839. X.SH SYNTAX
  840. pty
  841. X[
  842. X\fB\-qQve3EdDjJsStTrR0\fI\fP
  843. X] [
  844. X\fB\-h\fIhost\fP
  845. X] [
  846. X\fB\-O\fIremote\fP
  847. X] [
  848. X\fB\-p[cCdDeEnNrRsS780]\fI\fP
  849. X] [
  850. X\fB\-x[cCeEfFrRsSiuUwWxX]\fI\fP
  851. X] [
  852. X\fB\-ACHUVW\fI\fP
  853. X]
  854. program
  855. X[
  856. arg ...
  857. X]
  858. X.SH DESCRIPTION
  859. This man page describes the options
  860. for the
  861. X.B pty
  862. program.
  863. XFor a general overview of
  864. X.B pty,
  865. see the
  866. X.B pty(1)
  867. man page.
  868. XFor the effects of
  869. X.B pty
  870. without options,
  871. see the
  872. X.B pty-basic(1)
  873. man page.
  874. X
  875. Options
  876. X.B ACHUVW
  877. print the authorship notice,
  878. copyright notice,
  879. help notice,
  880. short usage summary,
  881. version number,
  882. and warranty information respectively.
  883. X
  884. X.B pty
  885. has quite a few flags,
  886. processed left to right.
  887. It processes its options
  888. with
  889. X.B getopt.
  890. It also consistently accepts capital letters to
  891. turn off options.
  892. It interprets some switches as turning on or even forcing others,
  893. as documented below.
  894. As an example,
  895. X.B\-d
  896. forces
  897. X.B\-T;
  898. it sets but doesn't force
  899. X.B\-J.
  900. To set
  901. X.B\-d
  902. and
  903. X.B\-j,
  904. use
  905. X.B\-dj
  906. in that order.
  907. X
  908. Here are the options:
  909. X.TP 12
  910. X\fB\-s\fI
  911. Session.
  912. When the connection is hung up or manually disconnected,
  913. X.B pty
  914. will patiently wait for a
  915. reconnection.
  916. X.I program
  917. won't notice a thing.
  918. X.B\-s
  919. sets but does not force
  920. X.B\-xu.
  921. It forces
  922. X.B\-E.
  923. This mode is described in detail in the
  924. X.B sess(1)
  925. man page.
  926. X.TP
  927. X\fB\-S\fI
  928. No session (default).
  929. When the connection is hung up,
  930. X.B pty
  931. will send a HUP to
  932. X.I program.
  933. X.B\-S
  934. sets but does not force
  935. X.B\-xU.
  936. X.TP
  937. X\fB\-d\fI
  938. X.B pty
  939. will assume it is already detached from the terminal.
  940. This forces
  941. X.B\-T;
  942. it sets but doesn't force
  943. X.B\-J.
  944. Instead of copying pseudo-terminal modes from
  945. the original terminal,
  946. X.B pty
  947. will set up a generic new-discipline line-at-a-time mode,
  948. as described in the
  949. X.B ttydfl(7)
  950. man page.
  951. X.TP
  952. X\fB\-D\fI
  953. X.B pty
  954. will assume that it is attached to a terminal (default).
  955. This sets
  956. X.B\-jt.
  957. X.TP
  958. X\fB\-e\fI
  959. Preserve
  960. standard error (file descriptor 2)
  961. and standard tty (file descriptor 3).
  962. X.TP
  963. X\fB\-3\fI
  964. Preserve fd 3, but point fd 2 at the pseudo-terminal.
  965. X.TP
  966. X\fB\-E\fI
  967. Direct both file descriptors to the pseudo-terminal (default).
  968. X(Actually,
  969. X.B pty
  970. will point standard error at the tty by name,
  971. but fd 3 at /dev/tty,
  972. so that various
  973. X.B ioctl()
  974. commands on fd 3 will work.)
  975. Also close all higher-numbered file descriptors.
  976. X.TP
  977. X\fB\-j\fI
  978. Job control (default): When
  979. X.I program
  980. stops,
  981. X.B pty
  982. stops with the same signal.
  983. When 
  984. X.B pty
  985. is restarted,
  986. it restarts
  987. X.I program.
  988. Note that
  989. X.B pty
  990. handles job control correctly:
  991. in particular, if it is told to continue while it is in the
  992. background, it will stop as many times as necessary until it
  993. is put into the foreground. (Most character-mode programs will
  994. hang or run in circles in the same situation.)
  995. X.TP
  996. X\fB\-J\fI
  997. No job control.
  998. If
  999. X.I program
  1000. stops,
  1001. X.B pty
  1002. will ignore it,
  1003. as if job control didn't exist.
  1004. Note that,
  1005. unlike the previous version of
  1006. X.B pty,
  1007. this version does not restart
  1008. X.I program
  1009. upon a reconnect.
  1010. X.TP
  1011. X\fB\-t\fI
  1012. X.B pty
  1013. will set the
  1014. original terminal to
  1015. no-echo, character-at-a-time mode (default).
  1016. X.TP
  1017. X\fB\-T\fI
  1018. X.B pty
  1019. will not touch the original terminal, if there is one.
  1020. In the simplest case this means that each character will
  1021. be echoed by two tty drivers.
  1022. It is always dangerous to put two programs in a pipe if both
  1023. change tty modes;
  1024. X.B pty,
  1025. X.B vi,
  1026. and
  1027. X.B more
  1028. are examples of such programs. If you use
  1029. X.B pty
  1030. in a pipe
  1031. with another tty-mode-changing program,
  1032. make sure to specify
  1033. X.B\-0
  1034. X(which is an abbreviation for
  1035. X.B\-eSTp0)
  1036. so that
  1037. X.B pty
  1038. will neither affect nor be affected by the other program.
  1039. If you use a pipe of ptys,
  1040. you should probably specify
  1041. X.B\-0
  1042. in all but one.
  1043. See
  1044. X.B condom(1)
  1045. for further details.
  1046. X.TP
  1047. X\fB\-q\fI
  1048. Quiet.
  1049. X.B pty
  1050. will print absolutely nothing on standard error,
  1051. unless
  1052. X.I program
  1053. uses standard error
  1054. and
  1055. X.B\-e
  1056. is set.
  1057. X.B pty
  1058. will communicate strange events through its exit code.
  1059. X.TP
  1060. X\fB\-Q\fI
  1061. Not quiet (default).
  1062. X.B pty
  1063. will generate bits of chatter about interesting
  1064. events,
  1065. such as reconnects.
  1066. X.TP
  1067. X\fB\-v\fI
  1068. Verbose.
  1069. X.B pty
  1070. will blabber on and on and on and on and on and on and on and on.
  1071. It keeps going,
  1072. and going,
  1073. and going,
  1074. and going ...
  1075. X.TP
  1076. X\fB\-r\fI
  1077. Read input (default).
  1078. X.TP
  1079. X\fB\-R\fI
  1080. Don't read input.
  1081. In this case
  1082. X.B pty
  1083. acts much like
  1084. X.B rsh \-n;
  1085. it only forwards output from
  1086. X.I program,
  1087. and does not attempt to read input.
  1088. This forces
  1089. X.B\-T.
  1090. X.TP
  1091. X\fB\-h\fIhost
  1092. Use
  1093. X.I host
  1094. for entries in utmp
  1095. and wtmp.
  1096. By default
  1097. X.B pty
  1098. uses
  1099. pty4.0,
  1100. or pieces together an address from TCPREMOTE if
  1101. it is running under an UCSPI-compliant TCP server.
  1102. This option may be disabled by the system administrator.
  1103. X.TP
  1104. X\fB\-O\fIremote
  1105. Use
  1106. X.I remote
  1107. for entries in scnow and sclog.
  1108. By default
  1109. X.B pty
  1110. uses unknown,
  1111. or pieces together an address from various environment variables
  1112. if it is running under any UCSPI-compliant connection tool.
  1113. This option may be disabled by the system administrator.
  1114. X.TP
  1115. X\fB\-p\fImmm
  1116. Set the
  1117. pseudo-terminal to modes specified by
  1118. X.I m.
  1119. Under
  1120. X.B\-d,
  1121. defaults are taken from the
  1122. current terminal;
  1123. under
  1124. X.B\-D,
  1125. defaults are as below.
  1126. X(See the
  1127. X.B ttydfl(7)
  1128. man page for more information.)
  1129. Predefined modes:
  1130. X.RS
  1131. X.TP 5
  1132. X.I c
  1133. Set cbreak (character-at-a-time) mode.
  1134. X.TP
  1135. X.I C
  1136. Do not set cbreak mode (default). 
  1137. X.TP
  1138. X.I d
  1139. Use the new discipline (default, breaking with tradition).
  1140. X.TP
  1141. X.I D
  1142. Use the old discipline, without job control or other fancy tty features.
  1143. X.TP
  1144. X.I e
  1145. XEcho characters (default).
  1146. X.TP
  1147. X.I E
  1148. Do not echo.
  1149. X.TP
  1150. X.I n
  1151. Change return to newline (default).
  1152. X.TP
  1153. X.I N
  1154. Do not change return to newline.
  1155. X.TP
  1156. X.I r
  1157. Set raw mode: do not produce signals, and pass eight-bit characters.
  1158. X.TP
  1159. X.I R
  1160. Set non-raw (``cooked'') mode (default).
  1161. X.TP
  1162. X.I s
  1163. Set line editing modes appropriate for a screen (default).
  1164. X.TP
  1165. X.I S
  1166. Do not set crt line editing modes.
  1167. X.TP
  1168. X.I 7
  1169. Set a 7-bit data path.
  1170. X.TP
  1171. X.I 8
  1172. Set an 8-bit data path (default).
  1173. X.TP
  1174. X.I 0
  1175. An abbreviation for pcrEND.
  1176. X.RE
  1177. X.TP
  1178. X\fB\-x\fIsss
  1179. Use security, experimental, or extended measures specified by
  1180. X.I s.
  1181. Some of these may be required or disabled by your system administrator.
  1182. XFurthermore,
  1183. these options may be changed arbitrarily in future or alternate
  1184. versions of
  1185. X.B pty,
  1186. so you should document any use of
  1187. X.B\-x
  1188. in programs and scripts meant to be portable.
  1189. Predefined values:
  1190. X.RS
  1191. X.TP 5
  1192. X.I c
  1193. Change the ownership and protections of the pty for the current user.
  1194. This option is meaningful only because
  1195. pseudo-ttys are in the filesystem.
  1196. This reflects several errors in the
  1197. UNIX system's pseudo-tty
  1198. model, but it's life.
  1199. X.TP
  1200. X.I C
  1201. Do not change pty ownership (default).
  1202. X.TP
  1203. X.I e
  1204. Do not guarantee readability of stderr to the pseudo-terminal.
  1205. This should be default, but such programs as
  1206. X.I csh
  1207. and
  1208. X.I more
  1209. insist on reading from stderr and dying horribly
  1210. if they fail,
  1211. even though half a teaspoon of common sense indicates
  1212. that the
  1213. X.B standard error
  1214. descriptor
  1215. is actually meant for printing
  1216. X.B errors.
  1217. In any case,
  1218. X.B\-xe
  1219. is useless under
  1220. X.B\-e.
  1221. X.TP
  1222. X.I E
  1223. Open stderr for reading and writing (default).
  1224. X.TP
  1225. X.I f
  1226. XFIONREAD flow-control.
  1227. X.B pty
  1228. will attempt to prevent buffer overflow in cbreak or cooked mode.
  1229. Note that this is not particularly efficient.
  1230. X(This option is rarely appropriate for interactive applications.)
  1231. X.TP
  1232. X.I F
  1233. No flow-control (default).
  1234. In this case
  1235. the tty driver
  1236. will beep and drop characters if there are already 256 in the buffer,
  1237. as usual.
  1238. X.TP
  1239. X.I r
  1240. Random pseudo-terminal searching (default).
  1241. This can provide a huge boost to speed and security.
  1242. If, for instance, there are 200 pseudo-ttys and 100 of them
  1243. are in use,
  1244. other programs will make
  1245. X100
  1246. X.B open()
  1247. calls and will always end up at a predictable spot,
  1248. while it will take
  1249. X.B pty
  1250. an average of just two
  1251. calls to find an unused tty.
  1252. It has been suggested to the author that
  1253. this has not been implemented before
  1254. because programmers don't realize
  1255. the virtues of modularity, are consequently too lazy to
  1256. write something like
  1257. X.B pty,
  1258. and don't want to take the effort for random pty searching
  1259. in every program that uses pseudo-terminals.
  1260. X.TP
  1261. X.I R
  1262. Straight pty searching, from the bottom on up.
  1263. X.TP
  1264. X.I s
  1265. XExtra-secure.
  1266. X.B pty
  1267. always starts by searching for a pseudo-tty which it can unconditionally
  1268. guarantee to be ``clean,'' i.e., not accessible to
  1269. any other users. If it cannot find a clean line, it
  1270. normally prints a warning and then uses any available tty.
  1271. Under this option it will die instead.
  1272. X.TP
  1273. X.I S
  1274. Not extra-secure.
  1275. This is the default.
  1276. X.TP
  1277. X.I i
  1278. Insecure.
  1279. Given this option,
  1280. X.B pty
  1281. won't bother looking for a clean tty first.
  1282. It will take the first tty it can find.
  1283. X.TP
  1284. X.I u
  1285. XEnter login name into /etc/utmp.
  1286. As a rule of thumb,
  1287. you should not do this for non-interactive sessions.
  1288. X.TP
  1289. X.I U
  1290. Do not use utmp (default).
  1291. X.TP
  1292. X.I w
  1293. Make an entry in /usr/adm/wtmp.
  1294. This probably isn't a good idea for general use,
  1295. as
  1296. connection time recorded in
  1297. X.I wtmp
  1298. is often pressed into unfortunate service as
  1299. a senseless basis for charged computer time.
  1300. X.TP
  1301. X.I W
  1302. Do not use wtmp (default).
  1303. X.TP
  1304. X.I x
  1305. Set exclusive use on the pty.
  1306. No processes can open the pty after this;
  1307. X.I program
  1308. can't even reopen
  1309. X/dev/tty!
  1310. X(It can use file descriptor 3 instead.)
  1311. This can be very important for security when
  1312. X.B pty
  1313. has not been installed by the system administrator.
  1314. It should be set all the time, but
  1315. too many programs rely on a filename for the terminal.
  1316. X.TP
  1317. X.I X
  1318. Do not set exclusive use (default).
  1319. X.RE
  1320. X.SH "SEE ALSO"
  1321. pty(1),
  1322. pty-basic(1),
  1323. tty(4)
  1324. END_OF_FILE
  1325. if test 9331 -ne `wc -c <'pty-opts.1'`; then
  1326.     echo shar: \"'pty-opts.1'\" unpacked with wrong size!
  1327. fi
  1328. # end of 'pty-opts.1'
  1329. fi
  1330. if test -f 'ptytty.c' -a "${1}" != "-c" ; then 
  1331.   echo shar: Will not clobber existing file \"'ptytty.c'\"
  1332. else
  1333. echo shar: Extracting \"'ptytty.c'\" \(9850 characters\)
  1334. sed "s/^X//" >'ptytty.c' <<'END_OF_FILE'
  1335. X#include <sys/types.h>
  1336. X#include <sys/file.h>
  1337. X#include <sys/ioctl.h>
  1338. X#include <signal.h>
  1339. X#include <errno.h>
  1340. extern int errno;
  1341. X#include "config/genericptr.h"
  1342. X#include "config/ttyopts.h"
  1343. X#include "ptytty.h"
  1344. X
  1345. static int ioc(fd,req,arg) /* non-interruptable ioctl */
  1346. int fd;
  1347. unsigned long req;
  1348. GENERICPTR arg;
  1349. X{
  1350. X int result;
  1351. X do
  1352. X   result = ioctl(fd,req,(char *) arg);
  1353. X while ((result == -1) && (errno == EINTR));
  1354. X return result;
  1355. X}
  1356. X
  1357. X#define IOC(f,req,arg) ioc((fd),(unsigned long) (req),(GENERICPTR) (arg))
  1358. X#define IOCR(f,req,arg) { if (IOC(f,req,arg) == -1) return -1; }
  1359. X
  1360. int tty_getctrl()
  1361. X{
  1362. X int fd;
  1363. X int dummy;
  1364. X
  1365. X#define ISTTY(f) (IOC(f,TIOCGPGRP,&dummy) == 0)
  1366. X
  1367. X if ((fd = dup(3)) != -1)
  1368. X   if (ISTTY(fd)) return fd; else close(fd);
  1369. X if ((fd = open("/dev/tty",O_RDWR)) != -1)
  1370. X   if (ISTTY(fd)) return fd; else close(fd);
  1371. X if ((fd = dup(0)) != -1)
  1372. X   if (ISTTY(fd)) return fd; else close(fd);
  1373. X if ((fd = dup(1)) != -1)
  1374. X   if (ISTTY(fd)) return fd; else close(fd);
  1375. X if ((fd = dup(2)) != -1)
  1376. X   if (ISTTY(fd)) return fd; else close(fd);
  1377. X return -1;
  1378. X}
  1379. X
  1380. int tty_spaceleft(fd)
  1381. int fd;
  1382. X{
  1383. X#ifdef FIONREAD
  1384. X long result;
  1385. X if (IOC(fd,FIONREAD,&result) == -1)
  1386. X   return -1;
  1387. X if (result > 200)
  1388. X   return 0;
  1389. X return 200 - result;
  1390. X#else
  1391. X errno = EIO;
  1392. X return -1; /*XXX*/
  1393. X#endif
  1394. X}
  1395. X
  1396. int tty_setexcl(fd)
  1397. int fd;
  1398. X{
  1399. X#ifdef TIOCEXCL
  1400. X return IOC(fd,TIOCEXCL,0);
  1401. X /* setting exclusive use is a bit unusual but it works */
  1402. X /* opening /dev/tty should still be allowed, though */
  1403. X#else
  1404. X errno = EIO;
  1405. X return -1;
  1406. X#endif
  1407. X}
  1408. X
  1409. int tctpgrp(fd,pid)
  1410. int fd;
  1411. int pid;
  1412. X{
  1413. X int pgrp;
  1414. X if ((pgrp = getpgrp(pid)) == -1)
  1415. X   return -1;
  1416. X return IOC(fdtty,TIOCSPGRP,&pgrp);
  1417. X}
  1418. X
  1419. int tty_forcefg(fd)
  1420. int fd;
  1421. X{
  1422. X int err;
  1423. X signal(SIGTTOU,SIG_DFL);
  1424. X /* XXX: what if TTOU is blocked? what if TTIN applies (e.g., under GNU)? */
  1425. X err = tctpgrp(fd,getpid()); /* could also use ,0 */
  1426. X signal(SIGTTOU,SIG_IGN);
  1427. X return err;
  1428. X}
  1429. X
  1430. int tty_dissoc(fd)
  1431. int fd;
  1432. X{
  1433. X int fdtty;
  1434. X if (fd != -1)
  1435. X   if (IOC(fd,TIOCNOTTY,0) == 0)
  1436. X     return 0;
  1437. X fdtty = open("/dev/tty",O_RDWR); /* XXX */
  1438. X if (fdtty == -1)
  1439. X   if (errno == EBUSY)
  1440. X     if (fd != -1)
  1441. X       return IOC(fd,TIOCNOTTY,0);
  1442. X     else
  1443. X       return -1;
  1444. X   else
  1445. X     return 0; /* XXX: in other words, if we're already dissociated, ok */
  1446. X if (IOC(fdtty,TIOCNOTTY,0) == 0)
  1447. X  {
  1448. X   close(fdtty);
  1449. X   return 0;
  1450. X  }
  1451. X close(fdtty);
  1452. X return -1;
  1453. X}
  1454. X
  1455. int tty_getmodes(fd,tmo)
  1456. int fd;
  1457. struct ttymodes *tmo;
  1458. X{
  1459. X#ifdef TTY_TERMIO
  1460. X IOCR(fd,TCGETA,&(tmo->ti))
  1461. X#else
  1462. X IOCR(fd,TIOCGETD,&(tmo->di))
  1463. X IOCR(fd,TIOCGETP,&(tmo->sg))
  1464. X IOCR(fd,TIOCGETC,&(tmo->tc))
  1465. X IOCR(fd,TIOCLGET,&(tmo->lb))
  1466. X IOCR(fd,TIOCGLTC,&(tmo->lt))
  1467. X#endif
  1468. X#ifdef TTY_WINDOWS
  1469. X IOCR(fd,TIOCGWINSZ,&(tmo->wi.ws))
  1470. X#endif
  1471. X#ifdef TTY_AUXCHARS
  1472. X IOCR(fd,TIOCGAUXC,&(tmo->au))
  1473. X#endif
  1474. X return 0;
  1475. X}
  1476. X
  1477. int tty_setmodes(fd,tmo)
  1478. int fd;
  1479. struct ttymodes *tmo;
  1480. X{
  1481. X#ifdef TTY_TERMIO
  1482. X IOCR(fd,TCSETA,&(tmo->ti))
  1483. X#else
  1484. X IOCR(fd,TIOCSETD,&(tmo->di))
  1485. X IOCR(fd,TIOCSETP,&(tmo->sg))
  1486. X IOCR(fd,TIOCSETC,&(tmo->tc))
  1487. X IOCR(fd,TIOCLSET,&(tmo->lb))
  1488. X IOCR(fd,TIOCSLTC,&(tmo->lt))
  1489. X#endif
  1490. X#ifdef TTY_WINDOWS
  1491. X IOCR(fd,TIOCSWINSZ,&(tmo->wi.ws))
  1492. X#endif
  1493. X#ifdef TTY_AUXCHARS
  1494. X IOCR(fd,TIOCSAUXC,&(tmo->au))
  1495. X#endif
  1496. X return 0;
  1497. X}
  1498. X
  1499. int tty_modifymodes(fd,tmonew,tmoold)
  1500. int fd;
  1501. struct ttymodes *tmonew;
  1502. struct ttymodes *tmoold;
  1503. X{
  1504. X#ifdef TTY_TERMIO
  1505. X IOCR(fd,TCSETA,&(tmonew->ti))
  1506. X   /* XXX: someone want to flesh this out a bit? */
  1507. X#else
  1508. X if (tmonew->di != tmoold->di)
  1509. X   IOCR(fd,TIOCSETD,&(tmonew->di))
  1510. X/* XXX: should make other tests dependent on new discipline? hmmm */
  1511. X if ((tmonew->sg.sg_flags != tmoold->sg.sg_flags)
  1512. X   ||(tmonew->sg.sg_ispeed != tmoold->sg.sg_ispeed)
  1513. X   ||(tmonew->sg.sg_ospeed != tmoold->sg.sg_ospeed)
  1514. X   ||(tmonew->sg.sg_erase != tmoold->sg.sg_erase)
  1515. X   ||(tmonew->sg.sg_kill != tmoold->sg.sg_kill))
  1516. X   IOCR(fd,TIOCSETP,&(tmonew->sg))
  1517. X if ((tmonew->tc.t_intrc != tmoold->tc.t_intrc)
  1518. X   ||(tmonew->tc.t_quitc != tmoold->tc.t_quitc)
  1519. X   ||(tmonew->tc.t_startc != tmoold->tc.t_startc)
  1520. X   ||(tmonew->tc.t_stopc != tmoold->tc.t_stopc)
  1521. X   ||(tmonew->tc.t_eofc != tmoold->tc.t_eofc)
  1522. X   ||(tmonew->tc.t_brkc != tmoold->tc.t_brkc))
  1523. X   IOCR(fd,TIOCSETC,&(tmonew->tc))
  1524. X if (tmonew->lb != tmoold->lb)
  1525. X   IOCR(fd,TIOCLSET,&(tmonew->lb))
  1526. X if ((tmonew->lt.t_suspc != tmoold->lt.t_suspc)
  1527. X   ||(tmonew->lt.t_dsuspc != tmoold->lt.t_dsuspc)
  1528. X   ||(tmonew->lt.t_rprntc != tmoold->lt.t_rprntc)
  1529. X   ||(tmonew->lt.t_flushc != tmoold->lt.t_flushc)
  1530. X   ||(tmonew->lt.t_werasc != tmoold->lt.t_werasc)
  1531. X   ||(tmonew->lt.t_lnextc != tmoold->lt.t_lnextc))
  1532. X   IOCR(fd,TIOCSLTC,&(tmonew->lt))
  1533. X#endif
  1534. X#ifdef TTY_WINDOWS
  1535. X if ((tmonew->wi.ws.ws_xpixel != tmoold->wi.ws.ws_xpixel)
  1536. X   ||(tmonew->wi.ws.ws_ypixel != tmoold->wi.ws.ws_ypixel)
  1537. X   ||(tmonew->wi.ws.ws_row != tmoold->wi.ws.ws_row)
  1538. X   ||(tmonew->wi.ws.ws_col != tmoold->wi.ws.ws_col))
  1539. X   IOCR(fd,TIOCSWINSZ,&(tmonew->wi.ws))
  1540. X#endif
  1541. X#ifdef TTY_AUXCHARS
  1542. X if ((tmonew->au.t_usemap != tmoold->au.t_usemap)
  1543. X   ||(tmonew->au.t_usest != tmoold->au.t_usest))
  1544. X   IOCR(fd,TIOCSAUXC,&(tmonew->au))
  1545. X#endif
  1546. X return 0;
  1547. X}
  1548. X
  1549. void tty_copymodes(tmonew,tmoold)
  1550. struct ttymodes *tmonew;
  1551. struct ttymodes *tmoold;
  1552. X{
  1553. X *tmonew = *tmoold; /* XXX: structure copying */
  1554. X}
  1555. X
  1556. void tty_modes2win(tmo,twi)
  1557. struct ttymodes *tmo;
  1558. struct ttywin *twi;
  1559. X{
  1560. X ;
  1561. X#ifdef TTY_WINDOWS
  1562. X twi->ws.ws_xpixel = tmo->wi.ws.ws_xpixel;
  1563. X twi->ws.ws_ypixel = tmo->wi.ws.ws_ypixel;
  1564. X twi->ws.ws_row = tmo->wi.ws.ws_row;
  1565. X twi->ws.ws_col = tmo->wi.ws.ws_col;
  1566. X#endif
  1567. X}
  1568. X
  1569. void tty_win2modes(twi,tmo)
  1570. struct ttywin *twi;
  1571. struct ttymodes *tmo;
  1572. X{
  1573. X ;
  1574. X#ifdef TTY_WINDOWS
  1575. X tmo->wi.ws.ws_xpixel = twi->ws.ws_xpixel;
  1576. X tmo->wi.ws.ws_ypixel = twi->ws.ws_ypixel;
  1577. X tmo->wi.ws.ws_row = twi->ws.ws_row;
  1578. X tmo->wi.ws.ws_col = twi->ws.ws_col;
  1579. X#endif
  1580. X}
  1581. X
  1582. void tty_zeromode(tmo)
  1583. struct ttymodes *tmo;
  1584. X{
  1585. X /* XXXXX: This is supposed to provide a mode in which the tty does */
  1586. X /* absolutely no processing. I don't think such a mode truly exists. */
  1587. X tty_mungemodes(tmo,3,0,2,0,3,0,3);
  1588. X}
  1589. X
  1590. void tty_mungemodes(tmo,cbreak,new,echo,crmod,raw,crt,p8bit)
  1591. struct ttymodes *tmo;
  1592. int cbreak;
  1593. int new;
  1594. int echo;
  1595. int crmod;
  1596. int raw;
  1597. int crt;
  1598. int p8bit;
  1599. X{
  1600. X#ifdef TTY_TERMIO
  1601. X if (crmod >= 2)
  1602. X   tmo->ti.c_iflag = (tmo->ti.c_iflag & ~ICRNL) | (ICRNL * (crmod == 3));
  1603. X if (echo >= 2)
  1604. X   tmo->ti.c_lflag = (tmo->ti.c_lflag & ~ECHO) | (ECHO * (echo == 3));
  1605. X if (cbreak >= 2)
  1606. X  {
  1607. X   tmo->ti.c_lflag = (tmo->ti.c_lflag & ~ICANON) | (ICANON * (cbreak == 2));
  1608. X   if (cbreak == 2) { tmo->ti.c_cc[VEOF] = 4; tmo->ti.c_cc[VEOL] = 0; }
  1609. X     /* XXX */
  1610. X   else { tmo->ti.c_cc[VMIN] = 1; tmo->ti.c_cc[VTIME] = 1; }
  1611. X  }
  1612. X if (raw >= 2)
  1613. X  {
  1614. X#define NOTIRAW (BRKINT | IGNBRK | IGNPAR | ISTRIP | IXON | IXANY | IXOFF)
  1615. X   tmo->ti.c_iflag = (tmo->ti.c_oflag & ~NOTIRAW) | (NOTIRAW * (raw == 2));
  1616. X   tmo->ti.c_oflag = (tmo->ti.c_oflag & ~OPOST) | (OPOST * (raw == 2));
  1617. X   tmo->ti.c_lflag = (tmo->ti.c_lflag & ~ISIG) | (ISIG * (raw == 2));
  1618. X  }
  1619. X if (crt >= 2)
  1620. X  {
  1621. X#define CRTECHO (ECHOE | ECHOCTL | ECHOKE)
  1622. X   tmo->ti.c_lflag = (tmo->ti.c_lflag & ~CRTECHO) | (CRTECHO * (crt == 3));
  1623. X  }
  1624. X /* XXX: p8bit: c_cflag? */
  1625. X /* XXX: new: c_line? */
  1626. X#else
  1627. X if (crmod >= 2)
  1628. X   tmo->sg.sg_flags = (tmo->sg.sg_flags & ~CRMOD) | (CRMOD * (crmod == 3));
  1629. X if (echo >= 2)
  1630. X   tmo->sg.sg_flags = (tmo->sg.sg_flags & ~ECHO) | (ECHO * (echo == 3));
  1631. X if (cbreak >= 2)
  1632. X   tmo->sg.sg_flags = (tmo->sg.sg_flags & ~CBREAK) | (CBREAK * (cbreak == 3));
  1633. X if (raw >= 2)
  1634. X   tmo->sg.sg_flags = (tmo->sg.sg_flags & ~RAW) | (RAW * (raw == 3));
  1635. X if (new >= 2)
  1636. X   tmo->di = ((new == 3) ? NTTYDISC : OTTYDISC);
  1637. X if (p8bit >= 2)
  1638. X  {
  1639. X   tmo->lb = (tmo->lb & ~PASS8) | (PASS8 * (p8bit == 3));
  1640. X   tmo->sg.sg_flags = (tmo->sg.sg_flags & ~(EVENP | ODDP))
  1641. X     | ((EVENP | ODDP) * (p8bit == 2)); /* have to do this for Suns */
  1642. X  }
  1643. X if (crt >= 2)
  1644. X   tmo->lb = (tmo->lb & ~(CRTBS | CRTERA | CRTKIL | CTLECH))
  1645. X                      | ((CRTBS | CRTERA | CRTKIL | CTLECH) * (crt == 3));
  1646. X#endif
  1647. X}
  1648. X
  1649. void tty_initmodes(tmo)
  1650. struct ttymodes *tmo;
  1651. X{
  1652. X#ifdef TTY_TERMIO
  1653. X /* Here we specify Ye Standard BSD Terminal Settings in termio format. */
  1654. X tmo->ti.c_iflag =
  1655. X   IGNBRK | BRKINT | IGNPAR | ISTRIP | IXON | IXANY | IXOFF;
  1656. X   /* XXX: IMAXBEL? */
  1657. X tmo->ti.c_oflag = OPOST | ONLCR;
  1658. X tmo->ti.c_lflag = ISIG | ICANON; /* XXX: | ECHO? */
  1659. X tmo->ti.c_cflag = CS7 | PARENB | PARODD;
  1660. X /* XXX: XTABS? */
  1661. X tmo->ti.c_cc[VINTR] = 3;
  1662. X tmo->ti.c_cc[VQUIT] = 28;
  1663. X tmo->ti.c_cc[VERASE] = 127;
  1664. X tmo->ti.c_cc[VKILL] = 21;
  1665. X tmo->ti.c_cc[VEOF] = 4;
  1666. X tmo->ti.c_cc[VEOL] = 0;
  1667. X tmo->ti.c_cc[VSTART] = 17;
  1668. X tmo->ti.c_cc[VSTOP] = 19;
  1669. X#ifdef VSUSP
  1670. X tmo->ti.c_cc[VSUSP] = 26;
  1671. X#endif
  1672. X#ifdef VDSUSP
  1673. X tmo->ti.c_cc[VDSUSP] = 25;
  1674. X#endif
  1675. X#ifdef VREPRINT
  1676. X tmo->ti.c_cc[VREPRINT] = 18;
  1677. X#endif
  1678. X#ifdef VDISCARD
  1679. X tmo->ti.c_cc[VDISCARD] = 15;
  1680. X#endif
  1681. X#ifdef VWEASE
  1682. X tmo->ti.c_cc[VWERASE] = 23;
  1683. X#endif
  1684. X#ifdef VLNEXT
  1685. X tmo->ti.c_cc[VLNEXT] = 22;
  1686. X#endif
  1687. X#ifdef VSTATUS
  1688. X tmo->ti.c_cc[VSTATUS] = 0;
  1689. X#endif
  1690. X#ifdef VEOL2
  1691. X tmo->ti.c_cc[VEOL2] = 0;
  1692. X#endif
  1693. X#else
  1694. X /* Here we specify Ye Standard BSD Terminal Settings. */
  1695. X
  1696. X tmo->di = OTTYDISC;
  1697. X tmo->sg.sg_ispeed = EXTB;
  1698. X tmo->sg.sg_ospeed = EXTB;
  1699. X tmo->sg.sg_erase = 127; /* del */
  1700. X tmo->sg.sg_kill = 21; /* ^U */
  1701. X tmo->sg.sg_flags = EVENP | ODDP; /* XXX: | XTABS? | ECHO???? */
  1702. X tmo->tc.t_intrc = 3; /* ^C */
  1703. X tmo->tc.t_quitc = 28; /* ^\ */
  1704. X tmo->tc.t_startc = 17; /* ^Q */
  1705. X tmo->tc.t_stopc = 19; /* ^S */
  1706. X tmo->tc.t_eofc = 4; /* ^D */
  1707. X tmo->tc.t_brkc = -1; /* undef */
  1708. X tmo->lb = DECCTQ; /* XXX: | PASS8? contradicts EVENP | ODDP */
  1709. X tmo->lt.t_suspc = 26; /* ^Z */
  1710. X tmo->lt.t_dsuspc = 25; /* ^Y */
  1711. X tmo->lt.t_rprntc = 18; /* ^R */
  1712. X tmo->lt.t_flushc = 15; /* ^O */
  1713. X tmo->lt.t_werasc = 23; /* ^W */
  1714. X tmo->lt.t_lnextc = 22; /* ^V */
  1715. X#endif
  1716. X#ifdef TTY_WINDOWS
  1717. X tmo->wi.ws.ws_xpixel = 0; /* Or read from TERMCAP? Hmmm */
  1718. X tmo->wi.ws.ws_ypixel = 0;
  1719. X tmo->wi.ws.ws_row = 0;
  1720. X tmo->wi.ws.ws_col = 0;
  1721. X#endif
  1722. X#ifdef TTY_AUXCHARS
  1723. X tmo->au.t_usest = 20; /* ^T */
  1724. X tmo->au.t_usemap = UST_LOAD1 | UST_LOAD5 | UST_LOAD15 | UST_RAWCPU
  1725. X   | UST_UPTIME | UST_PGRP | UST_CHILDS | UST_PCPU | UST_STATE;
  1726. X#endif
  1727. X}
  1728. END_OF_FILE
  1729. if test 9850 -ne `wc -c <'ptytty.c'`; then
  1730.     echo shar: \"'ptytty.c'\" unpacked with wrong size!
  1731. fi
  1732. # end of 'ptytty.c'
  1733. fi
  1734. if test -f 'sigsched.3' -a "${1}" != "-c" ; then 
  1735.   echo shar: Will not clobber existing file \"'sigsched.3'\"
  1736. else
  1737. echo shar: Extracting \"'sigsched.3'\" \(10067 characters\)
  1738. sed "s/^X//" >'sigsched.3' <<'END_OF_FILE'
  1739. X.TH sigsched 3
  1740. X.SH NAME
  1741. sigsched \- signal-schedule (non-preemptive threads) library
  1742. X.SH SYNTAX
  1743. X.B #include <sigsched.h>
  1744. X
  1745. ss_sig *\fBss_asap()\fR;
  1746. X.br
  1747. ss_sig *\fBss_signal(\fIsigno\fB)\fR;
  1748. X.br
  1749. ss_sig *\fBss_sigread(\fIfd\fB)\fR;
  1750. X.br
  1751. ss_sig *\fBss_sigwrite(\fIfd\fB)\fR;
  1752. X.br
  1753. ss_sig *\fBss_sigexcept(\fIfd\fB)\fR;
  1754. X
  1755. int \fBss_addsig(\fIsigno\fB)\fR;
  1756. X
  1757. int \fBss_schedvwait(\fIsig,t,flagi,i,p,wait\fB)\fR;
  1758. X.br
  1759. int \fBss_schedwait(\fIsig,t,i,wait\fB)\fR;
  1760. X.br
  1761. int \fBss_sched(\fIsig,t,i\fB)\fR;
  1762. X
  1763. int \fBss_schedonce(\fIsig,t,i\fB)\fR;
  1764. X
  1765. int \fBss_unschedv(\fIsig,t,flagi,i,p\fB)\fR;
  1766. X.br
  1767. int \fBss_unsched(\fIsig,t,i\fB)\fR;
  1768. X
  1769. void \fBss_externsetsig(\fIsig,x\fB)\fR;
  1770. X
  1771. int \fBss_exec()\fR;
  1772. X
  1773. void \fBss_forcewait()\fR;
  1774. X.br
  1775. void \fBss_unforcewait()\fR;
  1776. X
  1777. ss_thread \fI*t\fP;
  1778. X.br
  1779. ss_sig \fI*sig\fP;
  1780. X.br
  1781. ss_extern \fI*x\fP;
  1782. X.br
  1783. int \fIflagi\fP;
  1784. X.br
  1785. int \fIsigno\fP;
  1786. X.br
  1787. int \fIfd\fP;
  1788. X.br
  1789. ss_id \fIi\fP;
  1790. X.br
  1791. ss_idptr \fIp\fP;
  1792. X.br
  1793. int \fIwait\fP;
  1794. X.SH DESCRIPTION
  1795. X.B sigsched
  1796. implements the signal-schedule programming model,
  1797. otherwise known as non-preemptive threads,
  1798. otherwise known as event-based programming.
  1799. A thread is scheduled to execute upon receipt of a signal
  1800. X(occurrence of an event).
  1801. Separate threads do not interrupt each other.
  1802. All they can do is schedule more threads.
  1803. X
  1804. X.B sigsched
  1805. supports far more flexible signals than C normally provides
  1806. under UNIX.
  1807. X``File descriptor 2 is writable'' is a signal, for example.
  1808. XFurthermore, threads do not have to be written to handle a
  1809. signal at any moment, so code written to use
  1810. X.B sigsched
  1811. can be fully optimized.
  1812. In contrast, preemptive thread models (including
  1813. UNIX's usual signal handling) prevent optimizations involving global
  1814. variables.
  1815. X
  1816. In general, a ``signal'' is any persistent condition.
  1817. The ``file descriptor 2 is writable'' signal starts when the pipe
  1818. is created, persists at least until the next I/O, finishes when the pipe is
  1819. written to capacity, restarts when the pipe is read, and so on.
  1820. UNIX signals are examples of
  1821. X.I thread-lowered signals.
  1822. XFor example, SIGINT starts (is raised) when some process executes
  1823. kill(pid,SIGINT),
  1824. and finishes (is lowered) just before process pid calls the appropriate
  1825. signal handler (thread).
  1826. Note that if another process calls
  1827. kill(pid,SIGINT)
  1828. before the first one is delivered,
  1829. the signal merely persists.
  1830. It is not delivered twice, as after the first delivery the
  1831. signal condition has been turned off and can't be redelivered.
  1832. Any number of kill()s may be absorbed into
  1833. one delivery in this way.
  1834. X
  1835. With
  1836. X.B sigsched,
  1837. the program can schedule a thread to execute upon receipt of a signal.
  1838. X.B ss_schedvwait()
  1839. and
  1840. X.B ss_unschedv()
  1841. schedule and unschedule threads.
  1842. X.B ss_exec()
  1843. then executes one scheduled thread after another, as described below.
  1844. It exits when there are no ``important'' threads left to execute.
  1845. X
  1846. X.B ss_schedvwait(\fIsig,t,flagi,i,p,wait\fB)
  1847. schedules the thread
  1848. X.I t
  1849. to execute with integer identifier
  1850. X.I i
  1851. or pointer identifier
  1852. X.I p
  1853. as soon as condition
  1854. X.I sig
  1855. exists.
  1856. This is an ``important'' thread if
  1857. X.I wait
  1858. is nonzero.
  1859. X.I sig
  1860. is of type
  1861. X.B ss_sig *;
  1862. various functions produce signals of this type.
  1863. X.I t
  1864. is of type
  1865. X.B ss_thread *,
  1866. defined as a function returning void;
  1867. it is called as
  1868. X.I t(i)
  1869. if
  1870. X.I flagi
  1871. is nonzero,
  1872. or
  1873. X.I t(p)
  1874. if
  1875. X.I flagi
  1876. is zero.
  1877. X.I i
  1878. is an integer,
  1879. which must be zero if
  1880. X.I flagi
  1881. is;
  1882. X.I p
  1883. is a character pointer,
  1884. which must be a null pointer if
  1885. X.I flagi
  1886. is nonzero.
  1887. X.B <sigsched.h>
  1888. defines the
  1889. X.B ss_sig
  1890. and
  1891. X.B ss_thread
  1892. types;
  1893. it also abbreviates
  1894. int as
  1895. X.B ss_id
  1896. and char * as
  1897. X.B ss_idptr.
  1898. X.B ss_schedvwait
  1899. normally returns 0, but will return -1
  1900. in case of a memory allocation failure.
  1901. X
  1902. X.B ss_unschedv(\fIsig,t,flagi,i,p\fB)
  1903. unschedules the thread
  1904. X.I t
  1905. previously scheduled to execute with identifier
  1906. X.I i
  1907. or
  1908. X.I p
  1909. as soon as condition
  1910. X.I sig
  1911. existed.
  1912. X.I flagi,
  1913. X.I i,
  1914. and
  1915. X.I p
  1916. must follow the same rules as above.
  1917. X.B ss_unschedv
  1918. returns 0 if the unschedule was successful,
  1919. X1 if there was no such thread.
  1920. The effects are currently undefined if a thread is scheduled
  1921. more than once for the same signal with the same identifier.
  1922. X
  1923. X.B ss_exec()
  1924. executes one thread after another, with no interruptions.
  1925. It calls
  1926. X.I t(id)
  1927. only if, for some signal
  1928. X.I sig,
  1929. X(1)
  1930. X.I t(id)
  1931. is scheduled to execute upon
  1932. X.I sig;
  1933. X(2) condition
  1934. X.I sig
  1935. has existed sometime between the end of the last call
  1936. of a thread scheduled upon
  1937. X.I sig
  1938. and the beginning of this call to
  1939. X.I t(id).
  1940. If a
  1941. thread has just finished executing and
  1942. X.B ss_exec
  1943. can call one or more
  1944. threads under the above restrictions, it will choose one and call that,
  1945. unless every scheduled thread has a wait value of 0
  1946. X(i.e., there are no important threads scheduled).
  1947. In the latter case
  1948. X(including, for example, when there are no threads scheduled at all),
  1949. X.B ss_exec()
  1950. immediately returns 0.
  1951. It returns -1 in case of a memory allocation
  1952. failure; in that case its internal structures may be permanently
  1953. corrupted, and
  1954. X.B ss_exec
  1955. may not be called again in the same program.
  1956. X
  1957. If no threads can execute at a given moment,
  1958. but if some thread is
  1959. scheduled with a non-zero wait value,
  1960. X.B ss_exec
  1961. has to wait for a signal
  1962. to arrive.
  1963. As an optimization,
  1964. it will block the process until some
  1965. thread can execute,
  1966. rather than actively polling the set of signals.
  1967. X
  1968. Note that if several threads are scheduled to execute upon one signal,
  1969. and the signal suddenly exists, one of the threads will execute.
  1970. If the
  1971. signal turns off before the end of that thread, the other threads
  1972. scheduled upon the signal will not execute.
  1973. This is always true for
  1974. thread-lowered signals.
  1975. This behavior stands in
  1976. marked contrast to the behavior of interrupts---upon an interrupt,
  1977. all the scheduled threads would be executed.
  1978. X
  1979. XEach signal provides its own scheduling guarantees.
  1980. XFor instance, under
  1981. this implementation,
  1982. any (waiting) thread scheduled on the signal
  1983. X.I ss_asap()
  1984. will in fact execute at some point, provided that no thread
  1985. blocks or loops forever.
  1986. There is no way to keep pushing 
  1987. X.I ss_asap()
  1988. farther and farther into the future by scheduling other threads.
  1989. On the other hand,
  1990. X.I ss_asap()
  1991. will never flush out the other builtin signals.
  1992. X
  1993. X.B sigsched
  1994. provides several builtin signals:
  1995. X.B ss_asap()
  1996. returns a (pointer to a) signal which always exists.
  1997. X.B ss_signal(\fIsigno\fB)
  1998. returns a thread-lowered signal which is true when UNIX signal
  1999. X.I signo
  2000. is received.
  2001. X.B ss_sigread(\fIfd\fB)
  2002. returns a signal which is true when
  2003. X.I fd
  2004. is open and readable, as defined by
  2005. X.I select();
  2006. similarly for
  2007. X.B ss_sigwrite
  2008. and
  2009. X.B ss_sigexcept.
  2010. X
  2011. In order for
  2012. X.B sigsched
  2013. to handle UNIX signal
  2014. X.I signo,
  2015. you must call
  2016. X.B ss_addsig(\fIsigno\fB)
  2017. before calling
  2018. X.B ss_exec().
  2019. X.B ss_addsig
  2020. will discard the old signal handler;
  2021. later,
  2022. X.B ss_exec
  2023. will not restore the handler upon exiting, and may
  2024. leave the signal blocked or unblocked.
  2025. X.B ss_addsig
  2026. will return 0 normally,
  2027. X-1 if
  2028. X.I signo
  2029. is not in the right range for signals.
  2030. If another library makes use of
  2031. X.B ss_signal
  2032. with
  2033. X.B sigsched,
  2034. it should provide a mandatory initialization routine
  2035. which calls
  2036. X.B ss_addsig.
  2037. X
  2038. X.B ss_schedvwait
  2039. and
  2040. X.B ss_unschedv
  2041. can be abbreviated in common cases.
  2042. X.B ss_schedwait(\fIsig,t,i,wait\fB)
  2043. is the same as
  2044. X.B ss_schedvwait(\fIsig,t,1,i,(ss_idptr)0,wait\fB).
  2045. X.B ss_sched(\fIsig,t,i\fB)
  2046. is the same with
  2047. X.I wait
  2048. set to 0; it is commonly used for
  2049. handling user signals.
  2050. X.B ss_unsched(\fIsig,t,i\fB)
  2051. is the same as
  2052. X.B ss_unschedv(\fIsig,t,1,i,(ss_idptr)0\fB).
  2053. X
  2054. X.B ss_schedonce(\fIsig,t,i\fB)
  2055. is similar to
  2056. X.B ss_sched
  2057. but is in fact implemented on top of
  2058. X.B ss_schedvwait
  2059. with an independent mechanism.
  2060. XEach call to
  2061. X.B ss_schedonce
  2062. schedules
  2063. X.I t
  2064. upon a new signal which starts when
  2065. X.I sig
  2066. does and exists only until
  2067. X.I t(i)
  2068. is executed.
  2069. After the first execution the new signal disappears.
  2070. The new signal cannot be unscheduled.
  2071. X
  2072. X.B ss_forcewait()
  2073. tells
  2074. X.B sigsched
  2075. that something important is going on outside
  2076. X.B sigsched
  2077. and that
  2078. X.B ss_exec
  2079. should not exit.
  2080. X.B ss_unforcewait()
  2081. negates a previous
  2082. X.B ss_forcewait().
  2083. X.B ss_forcewait()
  2084. and
  2085. X.B ss_unforcewait()
  2086. control a counter, not a flag, so independent
  2087. libraries can use them, but each library should
  2088. be careful to use as many of one call as of the other.
  2089. These functions must not be used outside
  2090. X.B ss_exec().
  2091. X
  2092. X.B ss_externsetsig(sig,x)
  2093. creates a new signal
  2094. in the
  2095. X.B ss_sig
  2096. pointed to by
  2097. X.I sig.
  2098. X.I x
  2099. points to an
  2100. X.B ss_extern,
  2101. which is defined as follows in
  2102. X.B <sigsched.h>:
  2103. X.PP
  2104. X.EX
  2105. typedef struct {
  2106. X  int (*sched)();
  2107. X  int (*unsched)();
  2108. X  union { int n; char *c; } u;
  2109. X} ss_extern;
  2110. X.EE
  2111. X.PP
  2112. X.I sched
  2113. must be filled in with a scheduling function,
  2114. which is called as
  2115. X.I (*sched)(x,t,flagi,i,p,wait)
  2116. whenever
  2117. X.B ss_schedvwait(\fIsig,t,flagi,i,p,wait\fB)
  2118. is called;
  2119. similarly for
  2120. X.I unsched.
  2121. Use of
  2122. X.I u
  2123. is up to the caller.
  2124. X.I sched
  2125. and
  2126. X.I unsched
  2127. must observe the same rules as
  2128. X.B ss_schedvwait
  2129. and
  2130. X.B ss_unschedv
  2131. on any other signals: i.e., they must schedule threads upon
  2132. a persistent condition, make sure that
  2133. X.I ss_exec
  2134. does not exit if
  2135. any important threads are scheduled, etc.
  2136. Note that
  2137. X.B ss_externsetsig
  2138. records
  2139. X.I x
  2140. in
  2141. X.I sig,
  2142. so
  2143. X.I x
  2144. must point either to static memory or to
  2145. memory which remains allocated as long as
  2146. any thread is scheduled or executing upon
  2147. X.I sig.
  2148. Memory management of the
  2149. X.I sig
  2150. structure itself is up to the caller.
  2151. X
  2152. It is recommended that library
  2153. X.I foo
  2154. define a
  2155. X.B foo_sig
  2156. structure, which contains
  2157. X.B ss_sig
  2158. X.I sig,
  2159. X.B ss_extern
  2160. X.I x,
  2161. and any other necessary information for the signals defined by
  2162. X.I foo.
  2163. Then
  2164. X.B foo_setsig(\fI&fsig,otherinfo\fB),
  2165. where
  2166. X.I fsig
  2167. is a
  2168. X.B foo_sig,
  2169. should set up the
  2170. X.I otherinfo,
  2171. set
  2172. X.I fsig.x.u.c
  2173. to
  2174. X.I &fsig,
  2175. set
  2176. X.I fsig.x.sched
  2177. and
  2178. X.I fsig.x.unsched
  2179. appropriately,
  2180. and
  2181. finish with
  2182. X.B ss_externsetsig(&fsig.sig,&fsig.x).
  2183. That way the user can use
  2184. X.I &fsig.sig
  2185. as the signal argument to
  2186. X.B sigsched
  2187. functions,
  2188. and when
  2189. X.I foo's
  2190. scheduling routines are passed
  2191. X.I &fsig.x
  2192. as a first argument,
  2193. they can get to
  2194. X.I otherinfo
  2195. through
  2196. X.I fsig.x.u.c.
  2197. X
  2198. X.B sigsched
  2199. uses
  2200. X.B ralloc
  2201. for all allocation.
  2202. X.SH VERSION
  2203. sigsched 1.1, August 25, 1991.
  2204. X.SH AUTHOR
  2205. Placed into the public domain by Daniel J. Bernstein.
  2206. X.SH "SEE ALSO"
  2207. select(2),
  2208. sigvec(2),
  2209. ralloc(3)
  2210. END_OF_FILE
  2211. if test 10067 -ne `wc -c <'sigsched.3'`; then
  2212.     echo shar: \"'sigsched.3'\" unpacked with wrong size!
  2213. fi
  2214. # end of 'sigsched.3'
  2215. fi
  2216. echo shar: End of archive 6 \(of 9\).
  2217. cp /dev/null ark6isdone
  2218. MISSING=""
  2219. for I in 1 2 3 4 5 6 7 8 9 ; do
  2220.     if test ! -f ark${I}isdone ; then
  2221.     MISSING="${MISSING} ${I}"
  2222.     fi
  2223. done
  2224. if test "${MISSING}" = "" ; then
  2225.     echo You have unpacked all 9 archives.
  2226.     rm -f ark[1-9]isdone ark[1-9][0-9]isdone
  2227. else
  2228.     echo You still need to unpack the following archives:
  2229.     echo "        " ${MISSING}
  2230. fi
  2231. ##  End of shell archive.
  2232. exit 0
  2233.